<template>
	<view>
		<view class="box">
			<!-- 科室分类开始 -->
			<scroll-view class="items" :style="{height: wh +'px'}" scroll-y>
				<view :class="{item,active:active===index}" v-for="(item,index) in deptList" @click="deptFilter(index)"
					:key="item.id">
					{{item.label}}
				</view>
			</scroll-view>
			<!-- 科室分类结束 -->
			<view class="right">
				<!-- 搜索栏开始 -->
				<view class="search">
					<view class="search-bar ">
						<uni-search-bar cancelButton="none" v-model="topicTitle" placeholder="标题">
						</uni-search-bar>
						<uni-search-bar cancelButton="none" v-model="doctorName" placeholder="医生名">
						</uni-search-bar>
					</view>
					<view class="search-btn">
						<button
							style="width: 120rpx;font-size: 30rpx;text-align: center;line-height: 72rpx;margin-right: 20rpx;"
							@click="SearchEvent">搜索</button>
					</view>
				</view>
				<!-- 搜索栏结束 -->
				<view class="videoList">
					<scroll-view :style="{height: (wh - 56-20-10) +'px'}" scroll-y :lower-threshold="200"
						@scrolltolower="VideoListReachBottom">
						<!-- 视频项开始 -->
						<view v-if="videoList.length">
							<view class="video-item" @click="toVideoDetail(item)" v-for="(item,index) in videoList"
								:key="item.subjectCode">
								<video :src="item.videoUrl" :show-center-play-btn="false" :controls="false"></video>
								<text>{{item.topicTitle}}</text>
								<view class="box-doctor">
									<view class="doctor">
										医师:{{item.doctorName}}
									</view>
									<view class="category">
										类别:{{item.categoryName}}
									</view>
								</view>
							</view>
						</view>
						<!-- 视频项结束 -->
						<view class="empty" v-else>
							<uni-icons type="shop"></uni-icons>
							<text>现在还什么视频都没有, 去看看其他的吧</text>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex'
	import {
		getVideoListApi,
		getdeptListApi
	} from '../../common/api/lectureApi.js'
	import {
		getDoctorListApi
	} from '../../common/api/dictApi.js'
	export default {
		components: {},
		data() {
			return {
				wh: 0,
				videoList: [],
				active: 0,
				pageNum: 1,
				pageSize: 2,
				finish: false,
				deptList: [],
				doctorName: '',
				topicTitle: '',
				categoryCode: ''
			};
		},
		methods: {
			toVideoDetail(item) {
				//视频点击事件, 跳转视频详情页
				wx.navigateTo({
					url: `/subpkg/videoDetail/videoDetail?subjectCode=${item.subjectCode}`
				})
			},
			SearchEvent() {
				this.videoList = []
				this.finish = false
				this.pageNum = 1
				//发起请求
				this.getVideoList()
			},

			async getVideoList(callback) {
				if (this.finish) return
				//获取视频列表
				const res = await getVideoListApi(this.pageNum, this.doctorName, this.topicTitle, this.categoryCode)
				if (!res.data.records.length) {
					this.finish = true
					return uni.$showToast('已经到底啦');
				}
				this.videoList.push(...res.data.records)
				callback && callback()
			},
			VideoListReachBottom() {
				this.pageNum = this.pageNum + 1
				this.getVideoList()
			},
			async getdeptList() {
				const r = await getdeptListApi(16)
				this.deptList = r.data
				this.categoryCode = this.deptList[0].id
			},
			async deptFilter(index) {
				this.active = index
				if (this.categoryCode === this.deptList[index].id) return
				this.categoryCode = this.deptList[index].id
				this.pageNum = 1
				this.videoList = []
				this.finish = false
				this.getVideoList()
			},
			async getDoctorList() {
				const res = await getDoctorListApi("department")
			},
			Refresh() {
				this.pageNum = 1
				this.videoList = []
				this.deptList = []
				this.doctorName = ''
				this.topicTitle = ''
				this.finish = false
			}
		},
		async onLoad() {
			// 获取页面可用高度
			let getWindowInfo = uni.getWindowInfo()
			this.wh = getWindowInfo.windowHeight
			await this.getdeptList()
			this.getVideoList()
			this.getDoctorList()
		},
		onPullDownRefresh() {
			this.Refresh()
			this.getdeptList()
			this.getVideoList(uni.stopPullDownRefresh)
		}
	}
</script>

<style lang="scss" scoped>
	.items {
		width: 170rpx;
		background-color: #eeeeee;
		height: 100%;
		margin-right: 10rpx;
		font-size: 26rpx;

		.item {
			height: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			text-align: center;
		}

		.active {
			background-color: #f5f5f5;
			border-top-left-radius: 30rpx;
			border-botttom-left-radius: 30rpx;
		}
	}


	.box {
		display: flex;
		padding: 0 20rpx 0 0;

		.right {
			flex: 1;
			padding-top: 20rpx;
		}
	}

	.search {
		display: flex;
		height: 144rpx;

		button {
			display: flex;
			justify-content: center;
		}

		/deep/ .uni-searchbar {
			padding: 0;
		}

		.search-bar {
			display: flex;
			flex-direction: column;
			justify-content: end;
			flex: 1;
			overflow: auto;
			height: 144rpx;
		}

		.search-btn {
			margin-left: 10rpx;
			width: 120rpx;

			button {
				margin-top: 33%;
				box-shadow: 5px 5px 30px 1px #a79f9f;
			}
		}
	}

	.videoList {
		width: 100%;
		margin-top: 10rpx;

		.video-item {
			width: 100%;
			background-color: #f0f0f5;
			margin-bottom: 20rpx;
			font-size: 40rpx;

			video {
				width: 100%;
			}

			text {
				font-size: 35rpx;
			}

			.box-doctor {
				margin: 20rpx 0 0 0;
				padding-bottom: 20rpx;
				font-size: 25rpx;
				display: flex;
				justify-content: space-between;

				.category {
					padding-right: 10rpx;
				}
			}
		}
	}

	@mixin flex {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	@mixin height {
		/* #ifndef APP-NVUE */
		height: 100%;
		/* #endif */
		/* #ifdef APP-NVUE */
		flex: 1;
		/* #endif */
	}

	.box {
		@include flex;
	}

	.button {
		@include flex;
		align-items: center;
		justify-content: center;
		flex: 1;
		height: 35px;
		margin: 0 5px;
		border-radius: 5px;
	}

	.example-body {
		background-color: #fff;
		padding: 10px 0;
	}

	.button-text {
		color: #fff;
		font-size: 12px;
	}

	.popup-content {
		@include flex;
		align-items: center;
		justify-content: center;
		padding: 15px;
		height: 50px;
		background-color: #fff;
	}

	.popup-height {
		@include height;
		width: 200px;
	}

	.text {
		font-size: 12px;
		color: #333;
	}

	.popup-success {
		color: #fff;
		background-color: #e1f3d8;
	}

	.popup-warn {
		color: #fff;
		background-color: #faecd8;
	}

	.popup-error {
		color: #fff;
		background-color: #fde2e2;
	}

	.popup-info {
		color: #fff;
		background-color: #f2f6fc;
	}

	.success-text {
		color: #09bb07;
	}

	.warn-text {
		color: #e6a23c;
	}

	.error-text {
		color: #f56c6c;
	}

	.info-text {
		color: #909399;
	}

	.dialog,
	.share {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
	}

	.dialog-box {
		padding: 10px;
	}

	.dialog .button,
	.share .button {
		/* #ifndef APP-NVUE */
		width: 100%;
		/* #endif */
		margin: 0;
		margin-top: 10px;
		padding: 3px 0;
		flex: 1;
	}

	.dialog-text {
		font-size: 14px;
		color: #333;
	}

	.empty {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: rgba(0, 0, 0, 0.25);
		width: 100%;
		height: 100%;
		font-size: 28rpx;

		/deep/ uni-icons {
			text {
				font-size: 200rpx !important;
				color: rgba(0, 0, 0, 0.25) !important;
			}
		}
	}
</style>
